package com.jy.adscm.wechat.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.wechat.bean.QueryWechatSelfRepair;
import com.jy.adscm.wechat.bean.WechatRole;
import com.jy.adscm.wechat.bean.WechatSelfRepair;
import com.jy.adscm.wechat.service.WechatSelfRepairService;
import com.jy.adscm.wechat.service.WechatUserRoleService;
import com.jy.adscm.wechat.utils.RedisOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-09-26
 */
@RestController
@RequestMapping("adscm/wechat/wechatSelfRepair")
public class WechatSelfRepairController {
    @Autowired
    private RedisOperator redis;
    @Autowired
    WechatSelfRepairService wechatSelfRepairService;

    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody QueryWechatSelfRepair queryWechatSelfRepair, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        queryWechatSelfRepair.setOpenid(openid);
        Page<WechatSelfRepair> page=new Page(queryWechatSelfRepair.getCurrentPage(),queryWechatSelfRepair.getPageSize());
        page= wechatSelfRepairService.selectWechatSelfRepair(page,queryWechatSelfRepair);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody  WechatSelfRepair  wechatSelfRepair, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
       boolean result= wechatSelfRepairService.updateWechatSelfRepair(wechatSelfRepair);
        return  new SimpleCoreResponse("200","查询成功",result);
    }
    @RequestMapping("selectById/{id}")
    public SimpleCoreResponse selectById(@PathVariable Long id, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        WechatSelfRepair result= wechatSelfRepairService.selectWechatSelfRepairById(id);
        return  new SimpleCoreResponse("200","查询成功",result);
    }
    @RequestMapping("selectByPid/{id}")
    public SimpleCoreResponse selectByPid(@PathVariable Long id, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        WechatSelfRepair result= wechatSelfRepairService.selectByPid(id);
        return  new SimpleCoreResponse("200","查询成功",result);
    }

}

